﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MediaInfoLib;
using System.IO;

namespace MOJsdk
{
    public class MovieFileInfo
    {
        private string _VideoCodec, _AudioCodec, _framerate, _Format, _inform, _path, _witdh, _height, _strDuration, _size;
        private MediaInfo _mediaInfo;

        public MovieFileInfo(string FilePath)
        {
            LoadData(FilePath);
        }
        public MovieFileInfo(MovieFileInfo movieInfo)
        {
            LoadData(movieInfo.FileComplePath);
        }

        private void LoadData(string FilePath)
        {
            if (File.Exists(FilePath))
            {
                _path = FilePath;
                _mediaInfo = new MediaInfo();
                _mediaInfo.Open(_path);

                _VideoCodec = _mediaInfo.Get(StreamKind.Video, 0, "Format");
                _VideoCodec += "(" + _mediaInfo.Get(StreamKind.Video, 0, "Format/Info") + ")";

                _AudioCodec = _mediaInfo.Get(StreamKind.Audio, 0, "Format");
                _AudioCodec += "(" + _mediaInfo.Get(StreamKind.Audio, 0, "Format/Info") + ")";

                _inform = _mediaInfo.Inform();

                _framerate = _mediaInfo.Get(StreamKind.Video, 0, "FrameRate/String");
                _Format = _mediaInfo.Get(StreamKind.General, 0, "Format");
                _strDuration = _mediaInfo.Get(StreamKind.General, 0, "Duration");
                _size = _mediaInfo.Get(StreamKind.General, 0, "FileSize/String");

                _witdh = _mediaInfo.Get(StreamKind.Video, 0, "Width");
                _height = _mediaInfo.Get(StreamKind.Video, 0, "Height");
            }
        }

        public MediaInfo MediaInfoClass
        { get { return _mediaInfo; } }
        public string FileComplePath
        { get { return _path; } }
        public string VideoCodec
        { get { return _VideoCodec; } }
        public string AudioCodec
        {
            get { return _AudioCodec; }
        }
        public string FrameRate
        { get { return _framerate; } }
        public string FileFormat
        {
            get { return _Format; }
        }
        public string Resolution
        {
            get { return _witdh + "x" + _height; }
        }
        public string DurationMilliseconds
        {
            get { return _strDuration; }
        }
        public TimeSpan Duration
        {
            get { return TimeSpan.FromMilliseconds(Convert.ToDouble(_strDuration)); }
        }
        public string FileSize
        { get { return _size; } }
        public string Inform
        { get { return _inform; } }
        public string Width
        { get { return _witdh; } }
        public string Height
        { get { return _height; } }
    }
}
